package niuke;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-04-23
 * Time: 20:46
 */
public class Solution10 {
    public class Solution {
        ArrayList<ArrayList<Integer>> Print(TreeNode pRoot) {
            Queue<TreeNode> queue = new LinkedList<>();
            ArrayList<ArrayList<Integer>> ret = new ArrayList<>();
            if( pRoot == null) return ret;
            queue.offer( pRoot);
            while( !queue.isEmpty()){
                ArrayList<Integer> list = new ArrayList<>();
                int size = queue.size();

                while( size>0 ){
                    TreeNode tmp = queue.poll();
                    list.add(tmp.val);
                    if( tmp.left!=null) queue.offer(tmp.left);
                    if( tmp.right!=null) queue.offer(tmp.right);
                    size--;
                }
                ret.add(list);
            }
            return ret;
        }

    }
}
